package newcoder_exp.justPractise;

import org.junit.Test;

public class Ex1 {
    

    public class Solution {
        /**
         * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
         * 计算两个数之和
         * @param s string字符串 表示第一个整数
         * @param t string字符串 表示第二个整数
         * @return string字符串
         */
        public String solve (String s, String t) {
            StringBuilder sb = new StringBuilder();
            
            if (s.length() < t.length()) {
                String temp = s;
                s = t;
                t = temp;
            }
            
            int len1  = t.length(), len2 = s.length();
            
            char a, b;
            int sum = 0, flag = 0;
            for (int i = 0; i < len1; i++) {
                a = s.charAt(len2 - i - 1);
                b = t.charAt(len1 - i - 1);
                sum = num(a) + num(b) + flag; 
                flag = sum / 10;
                sum %= 10;
                sb.insert(0, sum);
            }
            for (int i = len1; i < len2; i++) {
                a = s.charAt(len2 - i - 1);
                sum = num(a) + flag; 
                flag = sum / 10;
                sum %= 10;
                sb.insert(0, sum);
            }
            if (flag != 0) {
                sb.insert(0, flag);
            }
            return sb.toString();
        }
        
        public int num(char s) {
            return s - '0';
        }
    }

    @Test
    public void test() {
        String a = "9";
        String b = "99999999999999999999999999999999999999999999999999999999999994";
        String res = new Solution().solve(a, b);
        System.out.println(res);
    }
}
